import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
    modules: {
    },
    state: {
        /**
         * 是否预览, 在路由守卫中判断 router-guard
         */
        preview: false,
        /**
         * 全局loading
         */
        loading: 0,
        wxLoaded: false
    },
    getters: {

    },
    mutations: {

        /**
         * 更新state的field字段为value
         * @param state
         * @param query
         * @param query.field
         * @param query.value
         */
        update: (state, query) => {
            state[query.field] = query.value;
        },
        wxLoaded: (state) => {
            state.wxLoaded = true;
        }
    },
    actions: {
        update: (context, query) => {
            return new Promise((resolve, reject) => {
                context.commit('update', query);
                resolve(query);
            });
        },
    }
});
